<?php 
class ControllerstoresGetnearbystores extends Controller { 
	public function index() {
		$lat = $this->request->get['positionlat'];
		$lng = $this->request->get['positionlng'];
		$kmperlng = 0.011631;
		$kmperlat = 0.009020;
		$minlat = $lat - $kmperlat;
		$maxlat = $lat + $kmperlat;
		
		$minlng = $lng - $kmperlng;
		$maxlng = $lng + $kmperlng;
		
		$this->load->model('stores/stores');	
		
		$nearbystores = $this->model_stores_stores->getNearbyStores($minlat,$maxlat,$minlng,$maxlng);
		
		foreach($nearbystores as $key => $v){
			//$argument = urlencode(base64_encode("store-id=".$v['store_id'].""));
			$nearbystores[$key]['store_url'] = $this->url->link('stores/productlist','store-id='.$v['store_id'],'SSL');
			$nearbystores[$key]['store_id'] = $v['store_id'];
			$nearbystores[$key]['name'] = $v['name'];
			$nearbystores[$key]['store_group'] = $v['store_group'];
			$nearbystores[$key]['address'] = $v['address'];
			$nearbystores[$key]['telephone'] = $v['telephone'];

		}
		 
	
		$this->response->setOutput(json_encode($nearbystores));		
  	}
}
?>